package com.wang.controller;

import com.wang.entity.OrderForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Classname BindController2
 * @Description TODO
 * @Date 2024/5/21 11:16
 * @Created by pc
 */
@Slf4j
@RestController
public class BindController2 {
    @PostMapping(value = "/order")
    public String order(@Valid @RequestBody OrderForm form, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return bindingResult.getFieldError().getDefaultMessage();
        }

        log.warn("order={}",form.toString());
        return "success";
    }
}
